package com.hopu.v1.controller.admin.subject;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.controller.front.question.FQuestionsCommentsController;
import com.hopu.v1.pojo.classes.Student;
import com.hopu.v1.pojo.common.R;

import com.hopu.v1.pojo.common.Save;
import com.hopu.v1.pojo.common.Update;
import com.hopu.v1.pojo.course.CourseHomework;
import com.hopu.v1.service.admin.classes.StudentService;
import com.hopu.v1.service.admin.subject.CourseHomeworkService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * 课程作业表(CourseHomework)表控制层
 *
 * @author makejava
 * @since 2024-09-25 19:33:03
 */
@RestController
@RequestMapping("/courseHomework")
public class CourseHomeworkController {
    /**
     * 服务对象
     */
    @Resource
    private CourseHomeworkService courseHomeworkService;

    @Autowired
    private StudentService studentService;

    /**
     * 学生列表
     *
     * @param
     * @param
     * @return
     */
    @GetMapping("/selectStudent")
    public R selectAll(String classId) {
        QueryWrapper<Student> studentQueryWrapper = new QueryWrapper<>();
        studentQueryWrapper.eq("class_id",classId);
        return R.ok(studentService.list(studentQueryWrapper));
    }

    /**
     * 获取作业列表
     *
     * @param page
     * @return 所有数据
     */
    @GetMapping("selectAll")
    public R selectAll(Page<CourseHomework> page,Integer courseId) {
        QueryWrapper<CourseHomework> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id",courseId);
        return R.ok(this.courseHomeworkService.page(page, queryWrapper));
    }


    @GetMapping("select")
    public R select(CourseHomework courseHomework) {
        return R.ok(this.courseHomeworkService.list(new QueryWrapper<>(courseHomework)));
    }
    /**
     * 新增数据
     *
     * @param courseHomework 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    public R insert(@Validated()CourseHomework courseHomework) {
        return R.ok(this.courseHomeworkService.save(courseHomework));
    }

    /**
     * 修改数据
     *
     * @param courseHomework 实体对象
     * @return 修改结果
     */
    @PostMapping("update")
    public R update(@Validated()CourseHomework courseHomework) {
        return R.ok(this.courseHomeworkService.updateById(courseHomework));
    }

    /**
     * 删除数据
     *
     * @param
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(int id) {
        return R.ok(this.courseHomeworkService.removeById(id));
    }
}

